package com.atguigu.lease.common.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * ClassName: MybatisMetaObjectHandler
 * Package: com.atguigu.lease.common.mybatisplus
 *
 * @Create 2025/10/29 17:17
 * @Author 阿瓒
 * @Version 1.0
 * Description:完成mybatis-plus自动填充数据设置
 */
@Component
public class MybatisMetaObjectHandler implements MetaObjectHandler {

    //插入数据时填充字段
    @Override
    public void insertFill(MetaObject metaObject) {
        /**
         * 参数1:meteObject:封装了当前操作的表 获取类的信息
         * 参数2:属性名 要给那个属性赋值
         * 参数3:属性类型 Date.class
         * 参数4:具体赋值 new Date()
         */
        this.strictInsertFill(metaObject,"createTime", Date.class,new Date());
    }

    //更新数据时填充字段
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject,"updateTime", Date.class,new Date());
    }
}
